package io.github.uicdb.et.item.curios;

import com.google.common.collect.Multimap;
import io.github.uicdb.et.ModEffects;
import io.github.uicdb.et.ModElements;
import io.github.uicdb.et.ModHelper;
import net.minecraft.ChatFormatting;
import net.minecraft.core.Holder;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.effect.MobEffectInstance;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.ai.attributes.Attribute;
import net.minecraft.world.entity.ai.attributes.AttributeModifier;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.phys.AABB;
import top.theillusivec4.curios.api.SlotContext;

import java.util.List;

public class SunlitItemItem extends CurioItem {
    public SunlitItemItem(Properties properties) {
        super(properties, 2);
    }

    @Override
    public void appendDefaultAttribute(Multimap<Holder<Attribute>, AttributeModifier> map, SlotContext slotContext, ResourceLocation id, ItemStack stack) {

    }

    @Override
    public void addAdditionTooltip(List<Component> tooltips, ItemStack stack) {
        tooltips.add(translate("sunlit").withStyle(ChatFormatting.LIGHT_PURPLE));
    }

    @Override
    public void curioTick(SlotContext slotContext, ItemStack stack) {
        LivingEntity entity = slotContext.entity();
        if (entity.level().getGameTime() % 20 == 0){
            var entitiesOfClass = ModHelper.randomSelect(entity.level().getEntitiesOfClass(LivingEntity.class, AABB.ofSize(entity.position(), 10, 10, 10)), entity.getRandom());
            if (!(entitiesOfClass instanceof Player) && !entity.equals(entitiesOfClass)) {
                //todo 如果对方身上有光元素，获得易伤
//                if(ModHelper.hasElement(entitiesOfClass, ModElements.LIGHT_ELEMENT.getElement())){
//                    entitiesOfClass.addEffect(new MobEffectInstance(ModEffects.INJURE,40,0));
//                }
            }
        }
        super.curioTick(slotContext, stack);
    }
}
